<!--
    Powered By nodePPT - This is probably the best web presentation tool so far!
    version: 0.9.8-3
    site: https://github.com/ksky521/nodePPT
-->
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>python_02_列表 - By </title>
    <link rel="stylesheet" media="all" href="./css/nodeppt2.0.css">
    <link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="./css/phone.css">
    <link rel="stylesheet" media="print" href="./css/pdf.css">
    <link rel="stylesheet" href="./js/highlight/styles/monokai_sublime.css">
    <link rel="stylesheet" href="./css/font-awesome.css">
</head>
<body>
<div class="slides">
    <slides id="container">
        <slide class="slide"><section class="slide-wrapper"><article class="flexbox vcenter">
<h1>python基础教程_02</h1>
<p><small>woniuppp</small></p>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>上节回顾</h2>

</hgroup><article>

<ul>
<li>学编程的方法</li>
<li>变量和语句</li>
<li>数字运算</li>
<li>字符串和格式化</li>
<li>获取用户输入</li>
<li>注释</li>
<li>流程控制 if else(嵌套)</li>
<li>逻辑 and or not is</li>
<li>while和for循环</li>
<li>break和continue</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>复习一下上节任务，小练习</h2>

</hgroup><article>

<ul>
<li>让用户输入数字，并且累加，输入求和</li>
<li>存10000块钱，年利率是3.25%，求多少年之后，存款能翻番</li>
<li>遗留问题，求平均分</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>下面问题来了</h2>
<h3>我想最后把每次输入的用户名和分数，都打印出来，怎么搞？</h3>

</hgroup><article>

<ul>
<li>现有的变量目测满足不了需求</li>
<li>我们需要新的数据结构XXX</li>
<li>XXX可以有顺序的存储一堆数量未知的数据</li>
<li>每次输入用户名和分数，我都塞到XXX里存起来，最后把整个XXX打印出来，并且计算平均值</li>
<li>bingo，目测可以搞定需求</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>先思考一下XXX需要什么能力才能满足我们</h2>

</hgroup><article>

<h3>XXX实现的能力就像排队买火车票一样</h3>
<ul>
<li>数量可以任意多----排多长的队伍，都OK {&amp;。}</li>
<li>可遍历</li>
<li>有序的----可以通过第X个，找到这个人</li>
<li>可以修改里面的值<ul>
<li>比如我可以和第3个人换个位置</li>
</ul>
</li>
<li>切片，获取其中一部分值<ul>
<li>第二个到第十个人，去另外一个地方排</li>
</ul>
</li>
<li>插入值，就是允许插队</li>
<li>得到元素数量----知道有多少人排队</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>XXX需要的能力</h2>
<ul>
<li>获取索引值----通过一个人的名字，能知道他是第几个</li>
<li>统计元素项目<ul>
<li>可以统计这个队列里，有多少儿童</li>
</ul>
</li>
<li>可以追加元素----新来一个人，去队尾站着</li>
<li>两个list合并<ul>
<li>窗口A不卖票了，A队伍和B队伍合并一起排队</li>
</ul>
</li>
<li>删除元素----一个人不想排了，直接走了</li>
<li>其他</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>List 隆重出场</h2>

</hgroup><article>

<h3>定义一个list</h3>
<pre><code class="python">
    >>> arr = ['C','python','js','css','html','node']
    >>> arr
    ['C','python','js','css','html','node']
    >>> arr[0]
    'C'
    >>> arr[1]
    'python'
    >>> arr[-1]
    'node'
    >>> arr[-3]
    'css'
</code></pre>
</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>list函数可以把字符串变成list</h2>
<h3>所以不要用list当作变量名</h3>

</hgroup><article>

<pre><code class="python">
    >>> arr = list('python')
    >>> arr
</code></pre>

<h3>可遍历</h3>
<pre><code class="python">
    for o in ['wd','pc','me']:
        print o
</code></pre>
</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>成员是否存在</h2>
<pre><code class="python">
    >>> 'wd' in ['wd','pc']
    >>> 
    >>> 'me' in ['wd','pc']
</code></pre>


</hgroup><article>

<h2>长度 最大值 最小值</h2>
<pre><code class="python">
    >>> arr = [1,2,3,6,123,345,-2,-8]
    >>> len(arr)
    >>> 
    >>> max(arr)
    >>> 
    >>> min(arr)
</code></pre>

<h3>任务：用之前的知识，实现in和这三个功能</h3>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>del删除list中的元素，</h2>

</hgroup><article>

<pre><code class="python">
    >>> arr = ['C','python','js','css','html','node']
    >>> del arr[2]
    >>> arr
</code></pre>

<h2>list可以相加和做乘法</h2>
<pre><code class="python">
    >>> arr = ['wd','pc']
    >>> arr*2
    >>> arr1 = ['me',1,2,3]
    >>> arr + arr1
</code></pre>
</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>修改值和切片</h2>

</hgroup><article>

<ul>
<li><pre><code class="python">
  >>> arr = ['C','python','js','css','html','node']
  >>> arr[0] = 'java'
  >>> arr
  >>> arr[-1] = 'ruby'
  >>> arr

  >>> arr[1]
  >>> arr[-1]
  >>> arr[-3]
</code></pre></li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>切片---获取list中一部分连续的数据</h2>

</hgroup><article>

<pre><code class="python">
    >>> arr = ['C','python','js','css','html','node']
    >>> arr[1:3]
    >>> 
    >>> arr[0:1]
    >>> 
    >>> arr[3:]
    >>> 
    >>> arr[-3:]
    >>> 
    >>> arr[:3]
    >>> 
    >>> arr[:]
</code></pre>
</article></section></slide>
<slide class="slide hasnote"><aside class="note">
<section>
<p>尝试负数的分片赋值</p>

</section>
</aside><section class="slide-wrapper"><hgroup>
<h2>切片可以赋值</h2>

</hgroup><article>

<pre><code class="python">
    >>> arr = ['C','python','js','css','html','node']
    >>> arr[2:4] = ['pc','wd']
    >>> arr
</code></pre>

<h2>切片可以插入和删除元素</h2>
<pre><code class="python">
    >>> arr = ['C','python','js','css','html','node']
    >>> arr[1:1] = ['pc','wd']
    >>> arr
    >>> arr[2:3] = []
</code></pre>
</article></section></slide>
<slide class="slide hasnote"><aside class="note">
<section>
<p>前面都是直接操作list，下面是list的一些方法
    注意区分，是修改的原List，还是返回值</p>

</section>
</aside><section class="slide-wrapper"><hgroup>
<h2>列表方法</h2>

</hgroup><article>

<ul>
<li>append 追加元素</li>
<li>count 统计次数</li>
<li>extend 扩展原列表</li>
<li>index 获取索引</li>
<li>insert 插入元素</li>
<li>pop remove 移出一个元素</li>
<li>reverse 反向存储</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>append 向list最后追加元素</h2>
<h3>没有返回值，修改原List</h3>

</hgroup><article>

<pre><code class="python">
    >>> arr = [1,2,3]
    >>> arr.append(4)
    >>> arr
</code></pre>


<h2>count 统计list中某个元素出现的次数</h2>
<h3>count返回值</h3>
<pre><code class="python">
    >>> arr = [1,2,3,4,43,3,1,2,3]
    >>> arr.count(2)
</code></pre>

<h3>任务:用之前的list知识，实现append和count的功能</h3>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>extend 扩展原列表</h2>
<pre><code class="python">
    >>> a = [1,2,3,4]
    >>> b = [5,6,7,8]
    >>> a.extend(b)
    >>> a
    #extend和append的区别
    >>> a.append(b)
    >>> a
</code></pre>

<p>extend和直接相加的区别</p>
<ul>
<li>extend没有返回值，是修改原List</li>
</ul>
<h3>任务:用之前的list知识，实现extend的功能</h3>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>index 从列表中找出某个值，返回第一个匹配项的索引位置</h2>
<h3>不存在的话，会报错，可以先用in检测</h3>
<pre><code class="python">
    >>> arr = [1,2,'a',3,5,1,56,45,234,6,7,234]
    >>> arr.index('a')
</code></pre>

<h2>insert 插队</h2>
<h3>arr.insert(位置，插入内容)</h3>
<pre><code class="python">
    >>> arr=[1,2,3,4,5,6,7]
    >>> arr.insert(3,'four')
    insert和下面效果一样

</code></pre>

<h3>任务:用之前的list知识，实现index和insert的功能</h3>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>pop 根据索引移除list中的元素，并且返回，默认删除最后一个</h2>
<h3>不传参数的话，和append正好相反</h3>
<pre><code class="python">
    >>> arr = [1,2,3,4]
    >>> arr.pop()
    >>> 
    >>> arr
    >>> arr1 = [1,2,3,4]
    >>> arr.pop(2)
    >>> 
    >>> arr
</code></pre>

<h3>arr.append(arr.pop())，arr没有变化~</h3>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>任务：实现队列和栈</h2>
<ul>
<li>先入先出</li>
<li>先入后出</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>remove根据值来删除元素，删除第一个匹配项</h2>
<h3>如果没有匹配项，报错</h3>
<pre><code class="python">
    >>> arr = ['a','b','c']
    >>> arr.remove('a')
    >>> arr

</code></pre>

<h2>reverse List反向 修改列表，不返回值</h2>
<pre><code class="python">
    >>> arr = [1,2,8,5,4]
    >>> arr.reverse()
    >>> 
    >>> arr
</code></pre>

<h3>任务:用之前的list知识，实现remove和reverse的功能</h3>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>引导复习一下list的知识</h2>
<ul>
<li>怎么定义一个list</li>
<li>in，len，max，min，del</li>
<li>切片</li>
<li>append, count, extend, index, insert, pop, remove, reverse</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<table>
<thead>
<tr>
<th style="text-align:left">方法</th>
<th style="text-align:center">原List</th>
<th style="text-align:right">返回值</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">append</td>
<td style="text-align:center">修改</td>
<td style="text-align:right">无</td>
<td></td>
</tr>
<tr>
<td style="text-align:left">count</td>
<td style="text-align:center">无</td>
<td style="text-align:right">返回</td>
<td></td>
</tr>
<tr>
<td style="text-align:left">extend</td>
<td style="text-align:center">修改</td>
<td style="text-align:right">无</td>
<td></td>
</tr>
<tr>
<td style="text-align:left">index</td>
<td style="text-align:center">修改</td>
<td style="text-align:right">无</td>
<td></td>
</tr>
<tr>
<td style="text-align:left">insert</td>
<td style="text-align:center">修改</td>
<td style="text-align:right">无</td>
<td></td>
</tr>
<tr>
<td style="text-align:left">pop</td>
<td style="text-align:center">修改</td>
<td style="text-align:right">返回删除的值</td>
<td></td>
</tr>
<tr>
<td style="text-align:left">remove</td>
<td style="text-align:center">修改</td>
<td style="text-align:right">无</td>
<td></td>
</tr>
<tr>
<td style="text-align:left">reverse</td>
<td style="text-align:center">修改</td>
<td style="text-align:right">无</td>
<td></td>
</tr>
</tbody>
</table>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>实践时间，操练起来</h2>
<ul>
<li>对一个list，求出最大的三个值</li>
<li>给一个字符串，反向打印出来</li>
<li>给定两个List，求出两个List里面，相同的元素</li>
<li>用户密码登陆系统，<ul>
<li>密码错误三次，锁定用户，不能登陆</li>
</ul>
</li>
<li>购物车<ul>
<li>用户登陆之后，才能看到商品列表</li>
<li>可以输入商品名，把商品加入购物车</li>
<li>打印购物车列表</li>
</ul>
</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<pre><code class="python">


</code></pre>
</article></section></slide>
        <slide class="slide thank-you-slide segue nobackground">
            <article class="flexbox vleft auto-fadein">
                <h2>Q &amp; A</h2>
                <h3>&lt;Thank You!&gt;</h3>
            </article>
        </slide>
        <slide class="slide logoslide dark nobackground">
            <article class="flexbox vcenter">
              <h2 style="color: white;">Powered By nodePPT v0.9.8-3</h2>
            </article>
          </slide>
        <div class="slideTip" id="tip"></div>
    </slides>
</div>
<canvas id="drawBoard" class="draw-board" width="900" height="700"></canvas>
<div class="progress"><span id="progress"></span></div>
<div id="_buttons">
    <div class="_btn-box" id="_btn-box" style="display:none;">
        <button class="fa fa-arrow-circle-left" id="_btn-prev"></button>
        <button class="fa fa-arrow-circle-right" id="_btn-next"></button>
        <button class="fa fa-paint-brush" id="_btn-brush"></button>
        <button class="fa fa-compress" id="_btn-overview" data-toggle="fa fa-expand"></button>
    </div>
    <button class="fa fa-bars" id="_btn-bar"  data-toggle="fa fa-close"></button>
</div>
<script src="./js/mixjs/lib/mix.0.3.0.min.js"></script>
<script>
var base = location.protocol + '//' + location.host;

var path = location.pathname.split('/').filter(function(v){
    return !!v;
});
path.pop();
path = path.join('/');
MixJS.config({
    baseURL: [ base, path, 'js'].join('/')+'/'
});

</script>
<script src="./js/mixjs/lib/event/broadcast.js"></script>
<script src="./js/nodeppt.js"></script>
<script>
Slide.init({
    containerID: 'container',
    drawBoardID: 'drawBoard',
    slideClass: '.slide',
    buildClass: '.build',
    progressID: 'progress',
    transition: 'slide1',
    width: 1100,
    dir: './',
    
    //打开下面的注释就开启postMessage方式
    //访问网址127.0.0.1:8080/ppt/demo#client
    control:{
        type: 'postMessage',
        args:{
            isControl:  false
        }
    },
    
    tipID: 'tip'
});
MixJS.loadJS('highlight/hljs-0.8.js',function(){
    hljs.tabReplace = '  ';
    hljs.initHighlightingOnLoad();
});
</script>

</body>
</html>
